<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Android基础--多媒体编程 | 不忘初心</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="导语  多媒体编程介绍">
<meta property="og:type" content="article">
<meta property="og:title" content="Android基础--多媒体编程">
<meta property="og:url" content="http://example.com/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%A4%9A%E5%AA%92%E4%BD%93%E7%BC%96%E7%A8%8B/index.html">
<meta property="og:site_name" content="不忘初心">
<meta property="og:description" content="导语  多媒体编程介绍">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2014-10-13T01:45:52.000Z">
<meta property="article:modified_time" content="2017-07-10T06:57:54.000Z">
<meta property="article:author" content="wxyass">
<meta property="article:tag" content="Android基础">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="不忘初心" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">不忘初心</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-基础/基础--多媒体编程" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%A4%9A%E5%AA%92%E4%BD%93%E7%BC%96%E7%A8%8B/" class="article-date">
  <time class="dt-published" datetime="2014-10-13T01:45:52.000Z" itemprop="datePublished">2014-10-13</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Android%E5%9F%BA%E7%A1%80/">Android基础</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      Android基础--多媒体编程
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h4 id="导语"><a href="#导语" class="headerlink" title="导语"></a>导语</h4><blockquote>
<p> 多媒体编程介绍  </p>
</blockquote>
<span id="more"></span> 

<h1 id="一、多媒体概念"><a href="#一、多媒体概念" class="headerlink" title="一、多媒体概念"></a>一、多媒体概念</h1><ul>
<li>文字、图片、音频、视频  </li>
</ul>
<h2 id="1-1、计算机图片大小的计算"><a href="#1-1、计算机图片大小的计算" class="headerlink" title="1.1、计算机图片大小的计算"></a>1.1、计算机图片大小的计算</h2><blockquote>
<p>图片大小 = 图片的总像素 * 每个像素占用的大小</p>
</blockquote>
<ul>
<li>单色图：每个像素占用1/8个字节</li>
<li>16色图：每个像素占用1/2个字节</li>
<li>256色图：每个像素占用1个字节</li>
<li>24位图：每个像素占用3个字节<br>##1.2、计算机图片详解</li>
<li>图片的大小 = 图片的像素 * 每个像素占用的大小</li>
<li>单色：只能表示两种颜色<ul>
<li>使用0和1表示黑与白</li>
<li>使用一个长度为1的二进制数字即可表示一个像素的颜色信息</li>
<li>每个像素占用1/8个字节</li>
</ul>
</li>
<li>16色：只能表示16种颜色<ul>
<li>使用16个数字对应这16种颜色</li>
<li>0~15,0000 ~ 1111，也就是说需要长度为4的二进制数字</li>
<li>每个像素占用1/2个字节</li>
</ul>
</li>
<li>256色：只能表示256种颜色<ul>
<li>使用256个数字对应256种颜色</li>
<li>0~255,0000 0000 ~ 1111 1111，也就是说需要长度为8的二进制数字</li>
<li>每个像素占用1个字节</li>
</ul>
</li>
<li>24位色：需要长度为24的二进制数字<ul>
<li>每个像素占用3个字节</li>
<li>R：0~255，占用1个字节</li>
<li>G：同上</li>
<li>B：同上</li>
</ul>
</li>
</ul>
<hr>
<p>#二、加载大图片到内存<br>###2.1、出现内存溢出问题</p>
<ul>
<li>Android系统以ARGB表示每个像素，所以每个像素占用4个字节，很容易内存溢出</li>
<li>android系统里面每个应用程序默认的vm虚拟机最大的heap空间 16M，如果应用程序占用的内存空间超过了16M  则OOM(out of memory）内存溢出。</li>
</ul>
<p>###2.2 如何解决加载大图片内存溢出问题？</p>
<ul>
<li>手机屏幕的分辨率要比图片的分辨率小很多。 只需要根据手机的分辨率把图片给压缩采样，加载到手机上就行了。步骤：<ol>
<li>计算手机屏幕的宽高</li>
<li>计算图片的宽高</li>
<li>计算图片的缩放比例</li>
<li>opts.inSampleSize = scale; 设置图片的缩放比例</li>
<li>加载图片到内存</li>
</ol>
</li>
<li>具体解析如下：<ul>
<li>Android内存中使用ARGB保存像素信息，每个像素占用4个字节</li>
<li>SD卡中图片像素大小：2400 * 3200 = 7680000</li>
<li>手机的屏幕像素大小：     320 * 480 = 153600</li>
<li>把SD卡图片先缩小，再加载，先计算图片的缩小比例<ul>
<li>2400 / 320 = 7.5</li>
<li>3200 / 480 = 6.67</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>##2.1对图片进行缩放</p>
<ul>
<li><p>获取屏幕宽高</p>
<pre><code>  //Display类提供关于屏幕尺寸和分辨率的信息。
  Display dp = getWindowManager().getDefaultDisplay();
  //获取屏幕的宽度尺寸，以像素为单位。(不建议使用，请使用getSize(Point) 代替)
  int screenWidth = dp.getWidth();
  //获取屏幕的高度尺寸，以像素为单位。(不建议使用，请使用getSize(Point) 代替)
  int screenHeight = dp.getHeight();
</code></pre>
</li>
<li><p>获取图片宽高 ????????????</p>
<pre><code>  //创建请求权对象
  Options opts = new Options();
  //请求图片属性但不申请内存，//不解析像素信息，只解析图片宽高，那么就不会申请内存去保存像素信息
  opts.inJustDecodeBounds = true;
  //api会解析图片的所有像素信息，把像素信息保存在内存中
  BitmapFactory.decodeFile(&quot;sdcard/dog.jpg&quot;, opts);
  //获取图片宽高
  int imageWidth = opts.outWidth;
  int imageHeight = opts.outHeight;
</code></pre>
</li>
<li><p>图片的宽高除以屏幕宽高，算出宽和高的缩放比例，取较大值作为图片的缩放比例</p>
<pre><code>  //计算缩小比例
  int scale = 1;
  int scaleX = imageWidth / screenWidth;
  int scaleY = imageHeight / screenHeight;
  //取较大值
  if(scaleX &gt;= scaleY &amp;&amp; scaleX &gt; 1)&#123;
      scale = scaleX;
  &#125;
  else if(scaleY &gt; scaleX &amp;&amp; scaleY &gt; 1)&#123;
      scale = scaleY;
  &#125;
</code></pre>
</li>
<li><p>按缩放比例加载图片</p>
<pre><code>  //设置缩放比例
  opts.inSampleSize = scale;
  //为图片申请内存
  opts.inJustDecodeBounds = false;
  //按照缩小后的比例来解析像素
  Bitmap bm = BitmapFactory.decodeFile(&quot;sdcard/dog.jpg&quot;, opts);

  //查找并初始化图片控件
  ImageView iv = (ImageView) findViewById(R.id.iv);
  //为图片重新添加内容
  iv.setImageBitmap(bm);
</code></pre>
</li>
</ul>
<p>–加载图片到内存，并显示在手机桌面上的示例–<br>    public class MainActivity extends Activity {</p>
<pre><code>    @Override
    protected void onCreate(Bundle savedInstanceState) &#123;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    &#125;

    public void click(View v)&#123;
        Options opts = new Options();
        //不解析像素信息，只解析图片宽高，那么就不会申请内存去保存像素信息
        opts.inJustDecodeBounds = true;
        //api会解析图片的所有像素信息，把像素信息保存在内存中
        BitmapFactory.decodeFile(&quot;sdcard/dog.jpg&quot;, opts);
        
        //获取图片宽高
        int imageWidth = opts.outWidth;
        int imageHeight = opts.outHeight;
        
        //获取屏幕宽高
        Display dp = getWindowManager().getDefaultDisplay();
        @SuppressWarnings(&quot;deprecation&quot;)
        int screenWidth = dp.getWidth();
        int screenHeight = dp.getHeight();
        
        //计算缩小比例
        int scale = 1;
        int scaleWidth = imageWidth / screenWidth;
        int scaleHeight = imageHeight / screenHeight;
        
        //取较大值
        if(scaleWidth &gt;= scaleHeight &amp;&amp; scaleWidth &gt; 1)&#123;
            scale = scaleWidth;
        &#125;
        else if(scaleWidth &lt; scaleHeight &amp;&amp; scaleHeight &gt; 1)&#123;
            scale = scaleHeight;
        &#125;
        
        //设置缩放比例
        opts.inSampleSize = scale;
        //为图片申请内存
        opts.inJustDecodeBounds = false;
        //按照缩小后的比例来解析像素
        Bitmap bm = BitmapFactory.decodeFile(&quot;sdcard/dog.jpg&quot;, opts);
        
        ImageView iv = (ImageView) findViewById(R.id.iv);
        iv.setImageBitmap(bm);
    &#125;
&#125;
</code></pre>
<hr>
<p>#三、在内存中创建图片的副本</p>
<blockquote>
<p>直接加载的bitmap对象是只读的，无法修改，要修改图片只能在内存中创建出一个一模一样的bitmap副本，然后修改副本</p>
</blockquote>
<pre><code>    //加载SD卡中的原图到内存,注意选个小的，不要内存溢出这个对象是只读的
    Bitmap srcBm = BitmapFactory.decodeFile(&quot;sdcard/photo3.jpg&quot;);
    //通过图片控件将原图显示到桌面，这个对象是只读的。
    iv_src.setImageBitmap(srcBm);
    
    //创建与原图大小一致的空白bitmap
    Bitmap copyBm = Bitmap.createBitmap(srcBm.getWidth(), srcBm.getHeight(), srcBm.getConfig());
    //定义画笔
    Paint paint = new Paint();
    //把纸铺在画版上
    Canvas canvas = new Canvas(copyBm);
    //把srcBm的内容绘制在copyBm上
    canvas.drawBitmap(srcBm, new Matrix(), paint);
    
    //将副本图片通过图片控件显示到桌面，这个对象是可读写的。
    iv_copy.setImageBitmap(copyBm);
</code></pre>
<p>–创建图片副本示例–</p>
<pre><code>public class MainActivity extends Activity &#123;

    @Override
    protected void onCreate(Bundle savedInstanceState) &#123;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //这个对象是只读的
        Bitmap bmSrc = BitmapFactory.decodeResource(getResources(), R.drawable.photo3);
    
        //1.创建与原图大小一致的bitmap对象，相当于创建了与原图大小一致的白纸
        Bitmap bmCopy = Bitmap.createBitmap(bmSrc.getWidth(), bmSrc.getHeight(), bmSrc.getConfig());
        //2.创建画笔对象
        Paint paint = new Paint();
        //3.创建画板对象，把白纸铺在画板上
        Canvas canvas = new Canvas(bmCopy);
        //4.开始作画，把原图内容画到白纸上
        canvas.drawBitmap(bmSrc, new Matrix(), paint);
    
        ImageView iv_src = (ImageView) findViewById(R.id.iv_src);
        iv_src.setImageBitmap(bmSrc);
        ImageView iv_copy = (ImageView) findViewById(R.id.iv_copy);
        iv_copy.setImageBitmap(bmCopy);
    &#125;
&#125;
</code></pre>
<p>##3.1对图片进行特效处理</p>
<ul>
<li><p>首先定义一个矩阵对象</p>
<pre><code>  Matrix mt = new Matrix();
</code></pre>
</li>
<li><p>缩放效果</p>
<pre><code>  //x轴缩放1倍，y轴缩放0.5倍
  mt.setScale(1, 0.5f);

  mt.setScale(2.0f, 2.0f);
</code></pre>
</li>
<li><p>旋转效果</p>
<pre><code>  //以副本图片为轴点，顺时旋转30度

  mt.setRotate(30,copyBm.getWidth()/2, copyBm.getHeight()/2);
</code></pre>
</li>
<li><p>平移</p>
<pre><code>  //x轴坐标+10，y轴坐标+20
  mt.setTranslate(10, 20);
</code></pre>
</li>
<li><p>镜面</p>
<pre><code>  //把X坐标都变成负数
  mt.setScale(-1, 1);
  //matrix.setScale(-1.0f, 1);
  //图片整体向右移
  mt.postTranslate(copyBm.getWidth(), 0);
</code></pre>
</li>
<li><p>倒影</p>
<pre><code>  //把Y坐标都变成负数
  mt.setScale(1, -1);
  //图片整体向下移
  mt.postTranslate(0, copyBm.getHeight());
</code></pre>
</li>
</ul>
<p>–图片特效示例–</p>
<pre><code>public class MainActivity extends Activity &#123;

    @Override
    protected void onCreate(Bundle savedInstanceState) &#123;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //这个对象是只读的
        Bitmap bmSrc = BitmapFactory.decodeResource(getResources(), R.drawable.photo3);
    
        //1.创建与原图大小一致的bitmap对象，相当于创建了与原图大小一致的白纸
        Bitmap bmCopy = Bitmap.createBitmap(bmSrc.getWidth(), bmSrc.getHeight(), bmSrc.getConfig());
        //2.创建画笔对象
        Paint paint = new Paint();
        //3.创建画板对象，把白纸铺在画板上
        Canvas canvas = new Canvas(bmCopy);
        //4.开始作画，把原图内容画到白纸上
        
        //4.1对图片进行特效处理
        //首先定义一个矩阵对象
        Matrix mt = new Matrix();
        //平移
        //mt.setTranslate(10, 20);
        
        //缩放
        //mt.setScale(0.5f,2);
        //mt.setScale(0.5f,2, bmCopy.getWidth()/2, bmCopy.getHeight()/2);
        
        //旋转
        //mt.setRotate(45,bmCopy.getWidth()/2, bmCopy.getHeight()/2);

        
        //镜面
        //mt.setScale(-1, 1); 
        //mt.postTranslate(bmCopy.getWidth(), 0);
        //倒影
        mt.setScale(1, -1);
        mt.postTranslate(0, bmCopy.getHeight());
        
        //4.2 把原图内容画到白纸上
        canvas.drawBitmap(bmSrc, mt, paint);
        
        ImageView iv_src = (ImageView) findViewById(R.id.iv_src);
        iv_src.setImageBitmap(bmSrc);
        ImageView iv_copy = (ImageView) findViewById(R.id.iv_copy);
        iv_copy.setImageBitmap(bmCopy);
    &#125;
&#125;
</code></pre>
<hr>
<p>#四、画画板,在图片副本上进行读写操作<br>###4.1、实现功能：记录用户触摸事件的XY坐标，绘制直线</p>
<ul>
<li><p>1、在手机屏幕上加载图片副本</p>
<pre><code>  //1将原画加载到内存
  Bitmap bmSrc = BitmapFactory.decodeResource(getResources(), R.drawable.bg);
  //2在内存中创建图片的副本
  bmCopy = Bitmap.createBitmap(bmSrc.getWidth(), bmSrc.getHeight(), bmSrc.getConfig());
  paint = new Paint();
  canvas = new Canvas(bmCopy);
  //作画
  canvas.drawBitmap(bmSrc, new Matrix(), paint);
  //3将副本图片显示在桌面上
  iv = (ImageView) findViewById(R.id.iv);
  iv.setImageBitmap(bmCopy);
</code></pre>
</li>
<li><p>2、给ImageView图片副本设置触摸侦听，得到用户的触摸事件，并获知用户触摸ImageView的坐标，实现在副本图片上划线</p>
<pre><code>  iv.setOnTouchListener(new OnTouchListener() &#123;
      
      @Override
      public boolean onTouch(View v, MotionEvent event) &#123;
          // TODO Auto-generated method stub
          switch (event.getAction()) &#123;//判断手指触屏事件
          //触摸屏幕
          case MotionEvent.ACTION_DOWN:
              //得到触摸屏幕时手指的坐标
              startX = (int) event.getX();
              startY = (int) event.getY();
              break;
          //在屏幕上滑动
          case MotionEvent.ACTION_MOVE:
              //用户滑动手指，坐标不断的改变，获取最新坐标
              int newX = (int) event.getX();
              int newY = (int) event.getY();
              //用上次onTouch方法得到的坐标和本次得到的坐标绘制直线
              canvas.drawLine(startX, startY, newX, newY, paint);
              //刷新桌面图片
              iv.setImageBitmap(copyBm);
              //改变每次画线的开始坐标
              startX = newX;
              startY = newY;
              break;
          &#125;
          //该触摸事件是否由此侦听处理
          return true;
      &#125;
  &#125;);
</code></pre>
</li>
<li><p>刷子效果，加粗画笔</p>
<pre><code>  public void flush(View v)&#123;
      paint.setStrokeWidth(8);
  &#125;
</code></pre>
</li>
<li><p>调色板，改变画笔颜色</p>
<pre><code>  public void green(View v)&#123;
      paint.setColor(Color.GREEN);
  &#125;
</code></pre>
</li>
<li><p>保存图片至SD卡</p>
<pre><code>  public void save(View v)&#123;
      File file = new File(&quot;sdcard/dazuo2.png&quot;);
      FileOutputStream fos;
      try &#123;
          fos = new FileOutputStream(file);
          //保存
          bmCopy.compress(CompressFormat.PNG, 100, fos);
      &#125; catch (FileNotFoundException e) &#123;
          e.printStackTrace();
      &#125;
      
      //发送sd卡就绪广播，触发sd卡的遍历
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_MEDIA_MOUNTED);
      intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));
      sendBroadcast(intent);
  &#125;
</code></pre>
</li>
<li><p>系统每次收到SD卡就绪广播时，都会去遍历sd卡的所有文件和文件夹，把遍历到的所有多媒体文件都在MediaStore数据库保存一个索引，这个索引包含多媒体文件的文件名、路径、大小</p>
</li>
<li><p>图库每次打开时，并不会去遍历sd卡获取图片，而是通过内容提供者从MediaStore数据库中获取图片的信息，然后读取该图片</p>
</li>
<li><p>系统开机或者点击加载sd卡按钮时，系统会发送sd卡就绪广播，我们也可以手动发送就绪广播</p>
<pre><code>  Intent intent = new Intent();
  intent.setAction(Intent.ACTION_MEDIA_MOUNTED);
  intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));
  sendBroadcast(intent);
</code></pre>
</li>
</ul>
<hr>
<p>#五、撕衣服</p>
<ul>
<li><p>原理：把穿内衣和穿外衣的照片重叠显示，内衣照在下面，用户滑动屏幕时，触摸的是外衣照，把手指经过的像素都置为透明，内衣照就显示出来了</p>
</li>
<li><p>步骤：</p>
</li>
<li><p>1.相对布局 外衣图片与内衣图片重叠，内衣上外衣下</p>
</li>
<li><p>2.在手机屏幕上加载外衣原画，并显示外衣图片副本</p>
</li>
<li><p>3.设置触摸侦听，移动的位置颜色变透明，</p>
<pre><code>  //初始化外衣图片控件
  iv = (ImageView) findViewById(R.id.iv);
  //为图片控件设置触摸侦听
  iv.setOnTouchListener(new OnTouchListener() &#123;
      
      @Override
      public boolean onTouch(View v, MotionEvent event) &#123;
          // TODO Auto-generated method stub
          switch (event.getAction()) &#123;//判断手指触屏事件
          //手指在屏幕上滑动时
          case MotionEvent.ACTION_MOVE:
              //得到相对图片的坐标
              int x = (int) event.getX();
              int y = (int) event.getY();
              //设置坐标方圆5像素都变为透明
              for (int i = -5; i &lt; 5; i++) &#123;
                  for (int j = -5; j &lt; 5; j++) &#123;
                      if(Math.sqrt(i*i + j*j) &lt;= 5)&#123;
                          //把指定坐标的像素置为指定颜色
                          if(x + i &lt; bmCopy.getWidth() &amp;&amp; x + i &gt;= 0 &amp;&amp; y + j &lt; bmCopy.getHeight() &amp;&amp; y + j &gt;= 0)&#123;
                              bmCopy.setPixel(x + i, y + j, Color.TRANSPARENT);
                              iv.setImageBitmap(bmCopy);
                          &#125;
                      &#125;
                  &#125;
              &#125;
              break;
          &#125;
          return true;
      &#125;
  &#125;);
</code></pre>
</li>
<li><p>每次只设置一个像素点太慢，以触摸的像素为圆心，半径为5画圆，圆内的像素全部置为透明</p>
<pre><code>  for (int i = -5; i &lt; 6; i++) &#123;
      for (int j = -5; j &lt; 6; j++) &#123;
          if(Math.sqrt(i * i + j * j) &lt;= 5)
              copyBm.setPixel(newX + i, newY + j, Color.TRANSPARENT);
      &#125;
  &#125;
</code></pre>
</li>
</ul>
<hr>
<p>#六、音乐播放器<br>##6.1播放服务</p>
<ul>
<li><p>1.创建音乐服务（播放音频的代码应该运行在服务中，定义一个播放服务MusicService）</p>
</li>
<li><p>1.1 MusicService服务里定义play、stop、pause、continuePlay等方法</p>
<pre><code>  //定义媒体播放器(MediaPlayer)控件的视图，此视图包含了一些典型的按钮，像&quot;播放(Play)/暂停(Pause)&quot;, &quot;倒带(Rewind)&quot;, &quot;快进(Fast Forward)&quot;与进度滑动器(progress slider)。

  //媒体播放器在服务启动时，就要被创建，要提全局
  MediaPlayer player;
  @Override
  public void onCreate() &#123;
      super.onCreate();
      player = new MediaPlayer();
      
  &#125;
  
  //服务内部定义开始音乐功能，
  private void play() &#123;
      //重置，进入空闲状态
      player.reset();
      try &#123;
          //设置音频文件来源，进入初始化状态
          player.setDataSource(&quot;sdcard/bzj.mp3&quot;);
          //player.setDataSource(&quot;http://192.168.15.77:8080/bzj.mp3&quot;);
          //进入准备状态
          //player.prepare();
          //异步准备
          player.prepareAsync();
          //异步准备需要设置准备侦听,准备好就开始播放
          player.setOnPreparedListener(new OnPreparedListener() &#123;
      
              @Override
              public void onPrepared(MediaPlayer mp) &#123;
                  //开始播放
                  player.start();
                  addTimer();
              &#125;
          &#125;);

      &#125; catch (Exception e) &#123;
          e.printStackTrace();
      &#125; 
  &#125;

  //服务内部定义暂停音乐功能
  private void pause() &#123;
      player.pause();
  &#125;

  private void stop() &#123;
      player.stop();
  &#125;

  //服务内部定义继续音乐功能
  private void continuePlay() &#123;
      player.start();
  &#125;
</code></pre>
</li>
<li><p>1.2 把play、stop、pause、continuePlay等方法这几个方法抽取成一个接口MusicInterface</p>
<pre><code>  public interface MusicControllerInterface &#123;

      void play();
      void pause();
      void continuePlay();
      void seekTo(int progress);
  &#125;
</code></pre>
</li>
<li><p>1.3 服务中定义一个中间人类，继承Binder，实现MusicInterface</p>
<pre><code>  class MusicController extends Binder implements MusicControllerInterface&#123;

      @Override
      public void play() &#123;
          MusicService.this.play();
          
      &#125;

      @Override
      public void pause() &#123;
          MusicService.this.pause();
      &#125;

      @Override
      public void continuePlay() &#123;
          MusicService.this.continuePlay();
          
      &#125;

      @Override
      public void seekTo(int progress) &#123;
          MusicService.this.seekTo(progress);
      &#125;
  &#125;
</code></pre>
</li>
<li><p>1.4 为音乐服务进行清单配置</p>
<pre><code>   &lt;service android:name=&quot;com.itheima.musicplayer.MusicService&quot;&gt;&lt;/service&gt;
</code></pre>
</li>
<li><ol start="2">
<li><p>Activity界面中混合启动startService服务（启动MusicService服务，再bind服务）</p>
<pre><code>   //UI界面已启动，执行此方法
   protected void onCreate(Bundle savedInstanceState) &#123;
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       //启动音乐服务意图（很显然是显示启动）
       Intent intent = new Intent(this, MusicService.class);
       //创建通讯频道对象，将用与获取中间人
       MusicConnection conn = new MusicConnection();
       
       sb = (SeekBar) findViewById(R.id.sb);
       sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() &#123;
           
           //停止划动
           @Override
           public void onStopTrackingTouch(SeekBar seekBar) &#123;
               //获取用户停止划动后的进度
               int progress = seekBar.getProgress();
               //改变音乐播放进度
               mci.seekTo(progress);
           &#125;
           //开始划动
           @Override
           public void onStartTrackingTouch(SeekBar seekBar) &#123;
           &#125;
           
           //正在划动
           @Override
           public void onProgressChanged(SeekBar seekBar, int progress,
                   boolean fromUser) &#123;
           &#125;
       &#125;);
       
       //------------------------------------------
       //混合启动
       //start是为了让进程变成服务进程
       startService(intent);
       //bind是为了拿到中间人对象
       bindService(intent, conn, BIND_AUTO_CREATE);
   &#125;
</code></pre>
</li>
</ol>
</li>
</ul>
<p>##6.2根据播放进度设置进度条</p>
<ul>
<li><p>获取当前的播放时间和当前音频的最长时间</p>
<pre><code>  int currentPosition = player.getCurrentPosition();
  int duration = player.getDuration();
</code></pre>
</li>
<li><p>播放进度需要不停的获取，不停的刷新进度条，使用计时器每500毫秒获取一次播放进度</p>
</li>
<li><p>发消息至Handler，把播放进度放进Message对象中，在Handler中更新SeekBar的进度</p>
<pre><code>  Timer timer = new Timer();
  timer.schedule(new TimerTask() &#123;
      
      @Override
      public void run() &#123;

          //获取歌曲当前播放的时间点
          int currentPosition = player.getCurrentPosition();
          //获取歌曲总时长
          int duration = player.getDuration();
          //获取消息对象
          //Message msg = Message.obtain();
          Message msg =MainActivity.handler.obtainMessage();
          //把播放进度存入Message中
          Bundle data = new Bundle();
          data.putInt(&quot;currentPosition&quot;, currentPosition);
          data.putInt(&quot;duration&quot;, duration);
          msg.setData(data);
          // 将消息发送到消息队列
          MainActivity.handler.sendMessage(msg);
      &#125;
  &#125;, 5, 500);
</code></pre>
</li>
<li><p>在Activity中定义Handler</p>
<pre><code>  static Handler handler = new Handler()&#123;
      public void handleMessage(android.os.Message msg) &#123;
          //取出消息携带的数据
          Bundle data = msg.getData();
          int currentPosition = data.getInt(&quot;currentPosition&quot;);
          int duration = data.getInt(&quot;duration&quot;);
      
          //设置播放进度
          sb.setMax(duration);
          sb.setProgress(currentPosition);
      &#125;;
  &#125;;
</code></pre>
</li>
</ul>
<p>##6.3拖动进度条改变播放进度</p>
<ul>
<li><p>1.在UI界面获取进度条控件，并对其设置拖动侦听，调用服务里的改变音乐播放进度方法(把进度参数传过去)</p>
<pre><code>   //初始化SeekBar音乐滚动条
   sb = (SeekBar) findViewById(R.id.sb);
   //给sb设置一个拖动侦听
   sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() &#123;
      //停止拖动时调用
      @Override
      public void onStopTrackingTouch(SeekBar seekBar) &#123;
          //获取用户停止划动后的进度
          int progress = seekBar.getProgress();
          //改变音乐播放进度，调用音乐服务抽取出来的接口方法，去改变音乐播放进度
          mci.seekTo(progress);
      &#125;
      //开始拖动时调用            
      @Override
      public void onStartTrackingTouch(SeekBar seekBar) &#123;
          
      &#125;
      //拖动的时候不断调用            
      @Override
      public void onProgressChanged(SeekBar seekBar, int progress,
              boolean fromUser) &#123;
          
      &#125;
  &#125;);    
</code></pre>
</li>
<li><p>2.定义方法：在音乐服务中定义根据进度参数改变音乐播放进度的方法</p>
<pre><code>  public void seekTo(int progress)&#123;
      player.seekTo(progress);
  &#125;
</code></pre>
</li>
</ul>
<hr>
<p>#七、视频播放器<br>##7.1SurfaceView</p>
<ul>
<li><p>对画面的实时更新要求较高</p>
</li>
<li><p>双缓冲技术：内存中有两个画布，A画布显示至屏幕，B画布在内存中绘制下一帧画面，绘制完毕后B显示至屏幕，A在内存中继续绘制下一帧画面</p>
</li>
<li><p>播放视频也是用MediaPlayer，不过跟音频不同，要设置显示在哪个SurfaceView</p>
<pre><code>  SurfaceView sv = (SurfaceView) findViewById(R.id.sv);
  SurfaceHolder sh = sv.getHolder();
                  
  MediaPlayer player = new MediaPlayer();
  player.reset();
  try &#123;
      player.setDataSource(&quot;sdcard/2.3gp&quot;);
      player.setDisplay(sh);
      player.prepare();
  &#125; catch (Exception e) &#123;
      e.printStackTrace();
  &#125;
  player.start();
</code></pre>
</li>
<li><p>SurfaceView是重量级组件，可见时才会创建</p>
</li>
<li><p>给SurfaceHolder设置CallBack，类似于侦听，可以知道SurfaceView的状态</p>
<pre><code>  //看做侦听，可以知道SurfaceView的状态，并执行相对应方法
  sh.addCallback(new Callback() &#123;
      //SurfaceView一旦不可见，就会被销毁,SurfaceView销毁时调用
      @Override
      public void surfaceDestroyed(SurfaceHolder holder) &#123;
          // TODO Auto-generated method stub
          
      &#125;
      //SurfaceView一旦可见，就会被创建SurfaceView创建时调用
      @Override
      public void surfaceCreated(SurfaceHolder holder) &#123;
          // TODO Auto-generated method stub
          
      &#125;
      
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width,
              int height) &#123;
          // TODO Auto-generated method stub
          
      &#125;
  &#125;);
</code></pre>
</li>
<li><p>SurfaceView一旦不可见，就会被销毁，一旦可见，就会被创建，销毁时停止播放，再次创建时再开始播放</p>
</li>
</ul>
<p>–视频播放器示例</p>
<pre><code>public class MainActivity extends Activity &#123;

    private MediaPlayer player;
    int progress = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) &#123;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //获取显示视频的控件
        SurfaceView sv = (SurfaceView) findViewById(R.id.sv);
        //获取控制器
        final SurfaceHolder holder = sv.getHolder();
        
//        Thread t = new Thread()&#123;
//            @Override
//            public void run() &#123;
//                try &#123;
//                    sleep(200);
//                &#125; catch (InterruptedException e) &#123;
//                    // TODO Auto-generated catch block
//                    e.printStackTrace();
//                &#125;
//                
//                runOnUiThread(new Runnable() &#123;
//                    
//                    @Override
//                    public void run() &#123;
//                        MediaPlayer player = new MediaPlayer();
//                        player.reset();
//                        try &#123;
//                            player.setDataSource(&quot;sdcard/2.3gp&quot;);
//                            //指定视频画面播放在哪个组件
//                            player.setDisplay(holder);
//                            player.prepare();
//                            player.start();
//                        &#125; catch (Exception e) &#123;
//                            // TODO Auto-generated catch block
//                            e.printStackTrace();
//                        &#125; 
//                        
//                    &#125;
//                &#125;);
//            &#125;
//        &#125;;
//        t.start();
        
        //给SurfaceHolder设置CallBack，类似于侦听，可以知道SurfaceView的状态
        holder.addCallback(new Callback() &#123;

            //SurfaceView摧毁时调用
            @Override
            public void surfaceDestroyed(SurfaceHolder holder) &#123;
                if(player != null)&#123;
                    //每次SurfaceView摧毁时记录播放进度
                    progress = player.getCurrentPosition();
                    player.stop();
                    player.release();
                    player = null;
                &#125;
            &#125;
            
            //SurfaceView创建时调用
            @Override
            public void surfaceCreated(SurfaceHolder holder) &#123;
                if(player == null)&#123;
                    player = new MediaPlayer();
                    player.reset();
                    try &#123;
                        //指定要播放的资源
                        player.setDataSource(&quot;sdcard/2.3gp&quot;);
                        //指定视频画面播放在哪个组件
                        player.setDisplay(holder);
                        //进入准备状态
                        player.prepare();
                        //跳到先前的进度
                        player.seekTo(progress);
                        //开始播放
                        player.start();
                    &#125; catch (Exception e) &#123;
                        e.printStackTrace();
                    &#125; 
                &#125;
            &#125;
            
            //SurfaceView结构改变时调用
            @Override
            public void surfaceChanged(SurfaceHolder holder, int format, int width,
                    int height) &#123;
                // TODO Auto-generated method stub
            &#125;
        &#125;);
    &#125;
&#125;
</code></pre>
<p>##7.2 VideoView 使用方法简单播放视频</p>
<pre><code>public class MainActivity extends Activity &#123;

    @Override
    protected void onCreate(Bundle savedInstanceState) &#123;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        VideoView vv = (VideoView) findViewById(R.id.vv);
        vv.setVideoPath(&quot;sdcard/2.3gp&quot;);
        vv.start();
    &#125;
&#125;
</code></pre>
<hr>
<p>#八、摄像头</p>
<ul>
<li><p>8.1启动系统提供的拍照程序</p>
<pre><code>  public void click1(View v)&#123;
      //隐式启动系统提供的拍照Activity
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      //设置照片的保存路径
      File file = new File(Environment.getExternalStorageDirectory(), &quot;haha.jpg&quot;); 
      intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); 
      //arg1:请求码，用于匹配
      startActivityForResult(intent, 0);
  &#125;
</code></pre>
</li>
<li><p>8.2启动系统提供的摄像程序</p>
<pre><code>  public void click2(View v)&#123;
      Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
      //设置摄像的保存路径
      File file = new File(Environment.getExternalStorageDirectory(), &quot;haha.3gp&quot;); 
      intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); 
      //设置保存视频文件的质量
      intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
      startActivityForResult(intent, 0);
  &#125;
</code></pre>
</li>
<li><p>8.3 启动系统提供的拍照Activity和启动系统提供的摄像Activity示例：</p>
<pre><code>  public class MainActivity extends Activity &#123;

      @Override
      protected void onCreate(Bundle savedInstanceState) &#123;
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      &#125;
  
      public void click1(View v)&#123;
          //启动系统提供的拍照Activity
          Intent intent = new Intent();    
          intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
          intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(&quot;sdcard/haha.jpg&quot;)));
          startActivityForResult(intent, 10);//开启拍照并设置请求码
      &#125;
      public void click2(View v)&#123;
          //启动系统提供的摄像Activity
          Intent intent = new Intent();    
          intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
          intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(&quot;sdcard/haha2.3gp&quot;)));
          intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
          startActivityForResult(intent, 20);//开启摄像并设置请求码
      &#125;
      
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) &#123;
          super.onActivityResult(requestCode, resultCode, data);
          //判断请求码，进行操作
          if(requestCode == 10)&#123;
              Toast.makeText(this, &quot;拍照完成&quot;, 0).show();
          &#125;
          else if(requestCode == 20)&#123;
              Toast.makeText(this, &quot;摄像完成&quot;, 0).show();
          &#125;
      &#125;
  &#125;
</code></pre>
</li>
</ul>
<p>#9 Camera照相机</p>
<ul>
<li>1.设置UI界面的Activity</li>
</ul>
<p>public class MainActivity extends Activity {<br>            private static final String TAG = “Camera”;<br>             private Camera mCamera;<br>             private CameraPreview mPreview;</p>
<pre><code>            @Override
            public void onCreate(Bundle savedInstanceState) &#123;
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
    
                if(checkCameraHardware(this))&#123;
                    // 创建摄像头实例
                    mCamera = getCameraInstance();
        
                    // 创建预览界面
                    mPreview = new CameraPreview(this, mCamera);
                    
                    
                    FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
                    //把SurfaceView设置为帧布局的子节点
                    preview.addView(mPreview);
                    
                 // 给拍照按钮设置点击侦听
                    Button captureButton = (Button) findViewById(R.id.button_capture);
                    captureButton.setOnClickListener(
                        new View.OnClickListener() &#123;
                            @Override
                            public void onClick(View v) &#123;
                                //自动对焦
                                mCamera.autoFocus(new AutoFocusCallback() &#123;
                                    
                                    //自动对焦完成时，此方法调用
                                    @Override
                                    public void onAutoFocus(boolean success, Camera camera) &#123;
                                        // 拍照
                                        mCamera.takePicture(null, null, mPicture);
                                        
                                    &#125;
                                &#125;);
                                
                            &#125;
                        &#125;
                    );
                &#125;
                else&#123;
                    Toast.makeText(this, &quot;连摄像头都没有，穷逼&quot;, 0).show();
                &#125;
            &#125;
    
    
        /** 检测是否有摄像头 */
        private boolean checkCameraHardware(Context context) &#123;
            //检测是否具有指定的系统功能
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA))&#123;
                // 有摄像头
                return true;
            &#125; else &#123;
                // 没有摄像头
                return false;
            &#125;
        &#125;
        
        /** 这是一个获取摄像头实例的安全的途径 */
        public static Camera getCameraInstance()&#123;
            Camera c = null;
            try &#123;
                //返回后置摄像头的实例，如果没有后置摄像头，返回空
                c = Camera.open(); // attempt to get a Camera instance
            &#125;
            catch (Exception e)&#123;
                // Camera is not available (in use or does not exist)
            &#125;
            return c; // returns null if camera is unavailable
        &#125;
    
        private PictureCallback mPicture = new PictureCallback() &#123;
    
            //摄像头照相方法执行时，会调用此方法
            @Override
            public void onPictureTaken(byte[] data, Camera camera) &#123;
    
                //指定相片保存的路径和文件名
                File pictureFile = new File(&quot;sdcard/ohohoho2.jpg&quot;);
    
                try &#123;
                    FileOutputStream fos = new FileOutputStream(pictureFile);
                    fos.write(data);
                    fos.close();
                &#125; catch (FileNotFoundException e) &#123;
                    Log.d(TAG, &quot;File not found: &quot; + e.getMessage());
                &#125; catch (IOException e) &#123;
                    Log.d(TAG, &quot;Error accessing file: &quot; + e.getMessage());
                &#125;
            &#125;
        &#125;;
    &#125;
</code></pre>
<ul>
<li>2.设置摄像头预览类CameraPreview</li>
</ul>
<p> /** 摄像头预览类 */<br>        public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {<br>            private static final String TAG = “Camera”;<br>            private SurfaceHolder mHolder;<br>            private Camera mCamera;</p>
<pre><code>        @SuppressWarnings(&quot;deprecation&quot;)
        public CameraPreview(Context context, Camera camera) &#123;
            super(context);
            mCamera = camera;
    
            // Install a SurfaceHolder.Callback so we get notified when the
            // underlying surface is created and destroyed.
            // 获取SurfaceView的holder
            mHolder = getHolder();
            // 设置侦听，侦听SurfaceView的摧毁和创建
            mHolder.addCallback(this);
            // 3.0之后，会自动设置
            mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        &#125;
    
        public void surfaceCreated(SurfaceHolder holder) &#123;
            // The Surface has been created, now tell the camera where to draw the preview.
            try &#123;
                //指定摄像头的预览界面显示在哪个SurfaceView中
                mCamera.setPreviewDisplay(holder);
                //开始预览
                mCamera.startPreview();
            &#125; catch (IOException e) &#123;
                Log.d(TAG, &quot;Error setting camera preview: &quot; + e.getMessage());
            &#125;
        &#125;
    
        public void surfaceDestroyed(SurfaceHolder holder) &#123;
            // empty. Take care of releasing the Camera preview in your activity.
        &#125;
    
        public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) &#123;
            // If your preview can change or rotate, take care of those events here.
            // Make sure to stop the preview before resizing or reformatting it.
    
            if (mHolder.getSurface() == null)&#123;
              // preview surface does not exist
              return;
            &#125;
    
            // stop preview before making changes
            try &#123;
                mCamera.stopPreview();
            &#125; catch (Exception e)&#123;
              // ignore: tried to stop a non-existent preview
            &#125;
    
            // set preview size and make any resize, rotate or
            // reformatting changes here
    
            // start preview with new settings
            try &#123;
                mCamera.setPreviewDisplay(mHolder);
                mCamera.startPreview();
    
            &#125; catch (Exception e)&#123;
                Log.d(TAG, &quot;Error starting camera preview: &quot; + e.getMessage());
            &#125;
        &#125;
    &#125;
</code></pre>
<ul>
<li><p>3.设置清单文件</p>
<pre><code>&lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; /&gt;
  &lt;uses-feature android:name=&quot;android.hardware.camera&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
</code></pre>
</li>
<li><p>4.布局文件</p>
<?xml version="1.0" encoding="utf-8"?>
<pre><code>  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:orientation=&quot;horizontal&quot;
      android:layout_width=&quot;fill_parent&quot;
      android:layout_height=&quot;fill_parent&quot;
      &gt;
    &lt;FrameLayout
      android:id=&quot;@+id/camera_preview&quot;
      android:layout_width=&quot;fill_parent&quot;
      android:layout_height=&quot;fill_parent&quot;
      android:layout_weight=&quot;1&quot;
      /&gt;
  
    &lt;Button
      android:id=&quot;@+id/button_capture&quot;
      android:text=&quot;拍照&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_gravity=&quot;center&quot;
      /&gt;
  &lt;/LinearLayout&gt;
</code></pre>
</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%A4%9A%E5%AA%92%E4%BD%93%E7%BC%96%E7%A8%8B/" data-id="ckvc340qs00635dfy7uw9glrf" data-title="Android基础--多媒体编程" class="article-share-link">Share</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Android%E5%9F%BA%E7%A1%80/" rel="tag">Android基础</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E5%86%85%E5%AE%B9%E6%8F%90%E4%BE%9B%E8%80%85ContentProvider/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Android基础--内容提供者ContentProvider
        
      </div>
    </a>
  
  
    <a href="/2014/10/13/%E5%9F%BA%E7%A1%80/%E5%9F%BA%E7%A1%80--%E6%9C%8D%E5%8A%A1%20Service/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Android基础--服务 Service</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Activity/">Activity</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android-Studio%E4%BB%8B%E7%BB%8D/">Android Studio介绍</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E5%9F%BA%E7%A1%80/">Android基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Android%E6%A8%A1%E6%9D%BF/">Android模板</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/BaseRecyclerViewAdapterHelper/">BaseRecyclerViewAdapterHelper</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Bug%E9%97%AE%E9%A2%98/">Bug问题</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Button/">Button</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/EditText/">EditText</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Fragment/">Fragment</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Gradle/">Gradle</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ListView/">ListView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MD%E8%AF%AD%E6%B3%95/">MD语法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MyEclipse/">MyEclipse</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/OSS/">OSS</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/RecyclerView/">RecyclerView</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/SQL%E5%9F%BA%E7%A1%80/">SQL基础</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/UI%E6%8E%A7%E4%BB%B6/">UI控件</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View/">View</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/ViewPager/">ViewPager</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/View%E7%AF%87/">View篇</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/as%E6%8A%A5%E9%94%99/">as报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/jar%E5%8C%85/">jar包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/targetSdkVersion/">targetSdkVersion</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%B8%83%E7%89%9B%E4%BA%91/">七牛云</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%BA%8C%E7%BB%B4%E7%A0%81/">二维码</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%88%A0%E9%99%A4%E5%9B%BE%E7%89%87%E7%BC%93%E5%AD%98/">删除图片缓存</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/">升级报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/">博客搭建</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%8E%BB%E6%8E%89v7%E5%8C%85/">去掉v7包</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/">图片处理</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%A4%9A%E5%AA%92%E4%BD%93/">多媒体</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AE%9A%E5%88%B6%E7%B1%BB/">定制类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B0%8F%E7%B1%B3%E6%89%8B%E6%9C%BA/">小米手机</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/">广播机制</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/">微博分享</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%89%93%E5%8C%85APK%E6%8A%A5%E9%94%99/">打包APK报错</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/">持久化存储</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%97%B6%E9%97%B4%E9%80%89%E6%8B%A9DatePicker/">时间选择DatePicker</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9C%8D%E5%8A%A1/">服务</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9D%83%E9%99%90/">权限</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/">构建基类</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%B5%8B%E8%AF%95/">测试</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%9B%91%E5%90%AC%E9%94%81%E5%B1%8F/">监听锁屏</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%B3%BB%E7%BB%9F%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC/">系统页面跳转</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/">艺术探索</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AF%BB%E5%8F%96txt/">读取txt</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%BE%93%E5%85%A5%E6%B3%95/">输入法</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8/">音乐播放器</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E9%BB%91%E9%A9%AC%E5%8D%AB%E5%A3%AB/">黑马卫士</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Activity/" rel="tag">Activity</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio/" rel="tag">Android Studio</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" rel="tag">Android Studio介绍</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E5%9F%BA%E7%A1%80/" rel="tag">Android基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android%E6%A8%A1%E6%9D%BF/" rel="tag">Android模板</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/BaseRecyclerViewAdapterHelper/" rel="tag">BaseRecyclerViewAdapterHelper</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Bug%E9%97%AE%E9%A2%98/" rel="tag">Bug问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Button/" rel="tag">Button</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/EditText/" rel="tag">EditText</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Fragment/" rel="tag">Fragment</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Gradle/" rel="tag">Gradle</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ListView/" rel="tag">ListView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MD%E8%AF%AD%E6%B3%95/" rel="tag">MD语法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MyEclipse/" rel="tag">MyEclipse</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OSS/" rel="tag">OSS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RecyclerView/" rel="tag">RecyclerView</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SQL%E5%9F%BA%E7%A1%80/" rel="tag">SQL基础</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/UI%E6%8E%A7%E4%BB%B6/" rel="tag">UI控件</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View/" rel="tag">View</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ViewPager/" rel="tag">ViewPager</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/View%E7%AF%87/" rel="tag">View篇</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/as%E6%8A%A5%E9%94%99/" rel="tag">as报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jar%E5%8C%85/" rel="tag">jar包</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/targetSdkVersion/" rel="tag">targetSdkVersion</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" rel="tag">七牛云</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" rel="tag">升级报错</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag">博客搭建</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" rel="tag">图片处理</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" rel="tag">多媒体</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" rel="tag">工作问题</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" rel="tag">广播机制</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" rel="tag">应用详情</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" rel="tag">微博分享</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" rel="tag">持久化存储</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9C%8D%E5%8A%A1/" rel="tag">服务</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9D%83%E9%99%90/" rel="tag">权限</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" rel="tag">构建基类</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%94%9F%E6%B4%BB/" rel="tag">生活</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BB%83%E6%89%8B/" rel="tag">练手</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" rel="tag">艺术探索</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" rel="tag">输入法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" rel="tag">高级技巧</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Activity/" style="font-size: 12.5px;">Activity</a> <a href="/tags/Android-Studio/" style="font-size: 10px;">Android Studio</a> <a href="/tags/Android-Studio%E4%BB%8B%E7%BB%8D/" style="font-size: 12.5px;">Android Studio介绍</a> <a href="/tags/Android%E5%9F%BA%E7%A1%80/" style="font-size: 20px;">Android基础</a> <a href="/tags/Android%E6%A8%A1%E6%9D%BF/" style="font-size: 10px;">Android模板</a> <a href="/tags/BaseRecyclerViewAdapterHelper/" style="font-size: 10px;">BaseRecyclerViewAdapterHelper</a> <a href="/tags/Bug%E9%97%AE%E9%A2%98/" style="font-size: 10px;">Bug问题</a> <a href="/tags/Button/" style="font-size: 10px;">Button</a> <a href="/tags/EditText/" style="font-size: 10px;">EditText</a> <a href="/tags/Fragment/" style="font-size: 18.75px;">Fragment</a> <a href="/tags/Gradle/" style="font-size: 10px;">Gradle</a> <a href="/tags/ListView/" style="font-size: 17.5px;">ListView</a> <a href="/tags/MD%E8%AF%AD%E6%B3%95/" style="font-size: 11.25px;">MD语法</a> <a href="/tags/MyEclipse/" style="font-size: 13.75px;">MyEclipse</a> <a href="/tags/OSS/" style="font-size: 11.25px;">OSS</a> <a href="/tags/RecyclerView/" style="font-size: 12.5px;">RecyclerView</a> <a href="/tags/SQL%E5%9F%BA%E7%A1%80/" style="font-size: 10px;">SQL基础</a> <a href="/tags/UI%E6%8E%A7%E4%BB%B6/" style="font-size: 15px;">UI控件</a> <a href="/tags/View/" style="font-size: 10px;">View</a> <a href="/tags/ViewPager/" style="font-size: 10px;">ViewPager</a> <a href="/tags/View%E7%AF%87/" style="font-size: 10px;">View篇</a> <a href="/tags/as%E6%8A%A5%E9%94%99/" style="font-size: 10px;">as报错</a> <a href="/tags/jar%E5%8C%85/" style="font-size: 10px;">jar包</a> <a href="/tags/targetSdkVersion/" style="font-size: 10px;">targetSdkVersion</a> <a href="/tags/%E4%B8%83%E7%89%9B%E4%BA%91/" style="font-size: 10px;">七牛云</a> <a href="/tags/%E5%8D%87%E7%BA%A7%E6%8A%A5%E9%94%99/" style="font-size: 10px;">升级报错</a> <a href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" style="font-size: 12.5px;">博客搭建</a> <a href="/tags/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/" style="font-size: 15px;">图片处理</a> <a href="/tags/%E5%A4%9A%E5%AA%92%E4%BD%93/" style="font-size: 12.5px;">多媒体</a> <a href="/tags/%E5%B7%A5%E4%BD%9C%E9%97%AE%E9%A2%98/" style="font-size: 16.25px;">工作问题</a> <a href="/tags/%E5%B9%BF%E6%92%AD%E6%9C%BA%E5%88%B6/" style="font-size: 12.5px;">广播机制</a> <a href="/tags/%E5%BA%94%E7%94%A8%E8%AF%A6%E6%83%85/" style="font-size: 10px;">应用详情</a> <a href="/tags/%E5%BE%AE%E5%8D%9A%E5%88%86%E4%BA%AB/" style="font-size: 10px;">微博分享</a> <a href="/tags/%E6%8C%81%E4%B9%85%E5%8C%96%E5%AD%98%E5%82%A8/" style="font-size: 13.75px;">持久化存储</a> <a href="/tags/%E6%9C%8D%E5%8A%A1/" style="font-size: 12.5px;">服务</a> <a href="/tags/%E6%9D%83%E9%99%90/" style="font-size: 10px;">权限</a> <a href="/tags/%E6%9E%84%E5%BB%BA%E5%9F%BA%E7%B1%BB/" style="font-size: 10px;">构建基类</a> <a href="/tags/%E7%94%9F%E6%B4%BB/" style="font-size: 11.25px;">生活</a> <a href="/tags/%E7%BB%83%E6%89%8B/" style="font-size: 11.25px;">练手</a> <a href="/tags/%E8%89%BA%E6%9C%AF%E6%8E%A2%E7%B4%A2/" style="font-size: 10px;">艺术探索</a> <a href="/tags/%E8%BE%93%E5%85%A5%E6%B3%95/" style="font-size: 10px;">输入法</a> <a href="/tags/%E9%AB%98%E7%BA%A7%E6%8A%80%E5%B7%A7/" style="font-size: 11.25px;">高级技巧</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">November 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">October 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">September 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">August 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">July 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">June 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">April 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">March 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/">February 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/09/">September 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/10/">October 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/04/">April 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/01/">January 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/05/">May 2012</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/11/03/Android%20Studio/Github%E4%B8%8A%E6%8F%90%E4%BA%A4%E4%BB%A3%E7%A0%81/">Github上提交代码</a>
          </li>
        
          <li>
            <a href="/2017/10/31/RecyclerView/BaseRecyclerViewAdapterHelper%E5%BA%93%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95/">BaseRecyclerViewAdapterHelper库的基本使用方法</a>
          </li>
        
          <li>
            <a href="/2017/10/31/%E5%9B%BE%E7%89%87%E5%A4%84%E7%90%86/%E4%B8%83%E7%89%9B%E4%BA%91--%E4%B8%83%E7%89%9B%E4%BA%91%E5%BF%AB%E9%80%9F%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87/">七牛云快速上传图片</a>
          </li>
        
          <li>
            <a href="/2017/10/31/Gradle/Gradle--Gradle%E6%B7%BB%E5%8A%A0%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93%E6%8A%A5%E5%BC%82%E5%B8%B8/">Gradle添加第三方库报异常</a>
          </li>
        
          <li>
            <a href="/2017/10/26/Android%20Studio/%E8%A7%A3%E5%86%B3Android-Studio-Gradle-%E9%94%99%E8%AF%AF-%E7%BC%96%E7%A0%81GBK%E7%9A%84%E4%B8%8D%E5%8F%AF%E6%98%A0%E5%B0%84%E5%AD%97%E7%AC%A6/">解决Android Studio Gradle 错误 编码GBK的不可映射字符</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 wxyass<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.4.1.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>